package br.com.megasena.infraestrutura;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class JpaFactory {
	private static EntityManagerFactory factory;
	private static String persistenceUnitName = "megaSena";
	private static EntityManager em;
	
	public static EntityManager create(){
		if(factory == null)
			factory = Persistence.createEntityManagerFactory(persistenceUnitName);
		em = factory.createEntityManager();
		return em;
	}
	
	/*public static EntityManager openManager(){
		if(factory == null)
			factory = Persistence.createEntityManagerFactory(persistenceUnitName);
		em = factory.createEntityManager();
		return em;
	}
	
	public static EntityManager getEntityManager(){
		return em;
	}*/
	
	public static void terminate(){
		factory.close();
		factory = null;
	}
}
